﻿#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QMovie>
#include <QResizeEvent>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QMovie *movie;
    // 加载动画
    movie = new QMovie(":/img/webm.webp");
    ui->label->setMovie(movie);
    ui->label->setScaledContents(true);
    movie->setCacheMode(QMovie::CacheAll);
    movie->setSpeed(100);
    movie->start();
    // 连接动画结束信号，重新开始，实现循环
    connect(movie, &QMovie::finished, movie, &QMovie::start);
    // 确保初始化时控件铺满窗口
    ui->label->resize(this->size());
    ui->widget->resize(this->size());
}

MainWindow::~MainWindow()
{
    delete ui;
}

// 重写resizeEvent，窗口大小变化时调整label和widget大小
void MainWindow::resizeEvent(QResizeEvent *event)
{
    QMainWindow::resizeEvent(event);

    QSize newSize = event->size();

    ui->label->resize(newSize);
    ui->widget->resize(newSize);
}
